/**  
 * GalleryAdapter.java
 * @version 1.0
 */
package com.kaiyidiannao.imagescale;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.Gallery;

import java.util.ArrayList;
import java.util.List;

public class GalleryAdapter extends BaseAdapter {

	private Context context;

    private List<String> imagePaths = new ArrayList<String>();

	public GalleryAdapter(Context context, List<String> imagePaths) {
		this.context = context;
        this.imagePaths = imagePaths;
	}

	@Override
	public int getCount() {
        return imagePaths.size();
	}

	@Override
	public Object getItem(int position) {
        //return  Uri.fromFile(new File(imagePaths.get(position)));
		return  BitmapFactory.decodeFile(imagePaths.get(position));
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		Bitmap bmp = (Bitmap) getItem(position);
		ZoomImageView view = new ZoomImageView(context, bmp.getWidth(), bmp.getHeight());
		view.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
		view.setImageBitmap(bmp);
		return view;
	}

}
